
var jingj=0;
var gh = (function() {
    var user_info_div;
  return {
    onload: function () {
        kobe=document.querySelector("#kobe");
        harden=document.querySelector("#harden");
        curry=document.querySelector("#curry");
        xiaoye=document.querySelector("#xiaoye");
        messi=document.querySelector("#messi");
        cRonaldo=document.querySelector("#cRonaldo");
        user_info_div = document.querySelector('#user_info');
        user_info_div.setAttribute("id","info")
        chrome.storage.local.get(['url'], function (result) {
            if (result.url===undefined){
                chrome.storage.local.set({url: "xiaoye"}, function() {
                });
            }
        });

        chrome.storage.local.get(['key'], function (result) {
            if (result.key===undefined){
                chrome.storage.local.set({key: 2}, function() {
                });
            }

        });

        kobe.onclick=kobeVideo;
        harden.onclick=hardenVideo;
        curry.onclick=curryVideo;
        xiaoye.onclick=xiaoyeVideo;
        messi.onclick=messiVideo;
        cRonaldo.onclick=cRonaldoVideo;
        jing();

    }
  };

    function messiVideo() {
        document.getElementById('info').innerHTML = '';
        chrome.storage.local.set({url: "m"}, function() {
        });
        jing()
    }
    function cRonaldoVideo() {
        document.getElementById('info').innerHTML = '';
        chrome.storage.local.set({url: "c"}, function() {
        });
        jing()
    }

    function kobeVideo() {
        document.getElementById('info').innerHTML = '';
        chrome.storage.local.set({url: "k"}, function() {
        });
        jing()
    }
    function hardenVideo() {
        document.getElementById('info').innerHTML = '';
        chrome.storage.local.set({url: "h"}, function() {
        });
        jing()
    }
    function curryVideo() {
        document.getElementById('info').innerHTML = '';
        chrome.storage.local.set({url: "curry"}, function() {
            jing()
        });

    }
    function xiaoyeVideo() {
        document.getElementById('info').innerHTML = '';
        chrome.storage.local.set({url: "xiaoye"}, function() {
            jing()
        });

    }
    function jing() {
        var video=document.createElement('div');
        video.setAttribute("id","vid");
        chrome.storage.local.get(['key'], function(result) {
            chrome.storage.local.get(['url'], function (resultt) {
                var videoKey=result.key;
                var videoUrl=resultt.url;
                if (resultt.url===undefined) {
                    videoUrl="xiaoye";
                }
                if (result.key===undefined) {
                    videoKey=1;
                }

                video.innerHTML = "<video  src='http://101.34.184.45:80/static/videos/" + videoUrl + videoKey + ".mp4' width='350' height='200' loop autoplay></video> ";
                user_info_div.appendChild(video);
                jingj = result.key;
                jingj++;
                if (jingj === 4) {
                    jingj = 1;
                }
                chrome.storage.local.set({key: jingj}, function () {
                });
            });
        });
  }
})();



window.onload = gh.onload;